package com.zhs.blog.controller;

import com.zhs.blog.domain.ResponseResult;
import com.zhs.blog.domain.entity.User;
import com.zhs.blog.enu.AppHttpCodeEnum;
import com.zhs.blog.exception.SystemException;
import com.zhs.blog.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: BlogLoginController
 * @Descripiton: TODO
 * @Author: 小郑
 * @Date： 2025/5/10 15:37
 * @Version：1.8
 **/
@RestController
public class BlogLoginController {
    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        if(!StringUtils.hasText(user.getUserName())){
            // 提示， 必须要传入用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    /**
     * 退出接口
     * 删除Redis中的信息
     * @return
     */
    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }


}

